Extract hourly Copernicus Climate data - Python API

Published on Apr 02, 2020 | Bikesh Bade | 2923 Views

Copernicus is the European Union's Earth Observation Programme, looking at our planet and its environment. Vast amounts of global data from satellites and from ground-based, airborne and seaborne measurement systems are being used to provide information to help service providers, public authorities and other international organizations improve the quality of life.

 

Copernicus service provides programmatic access to Climate Data Store(CDS) data with the climate Data Store Application Program Interface.

 

1. To use API service Copernicus service you have to register in the CDS. 
2. For registration follow self-register at the CDS registration page.  
3. After registration Login and Retrieve the API-key. 
4. Create the file $HOME/.cdsapirc (in your Unix/Linux environment). 
5. Create the file C:/.cdsapirc (in your Windows environment) 
6. The file should look like:

           url: https://cds.climate.copernicus.eu/api/v2

           key: {uid}:{api-key}

 

The CDS API client is a python based library. It provides support for both Python 2.7.x and Python 3.You can Install the CDS API client via the package management system PIP, by running on Unix/Linux/Windows the command shown in the below:

 

pip install cdsapi

 

Once the CDS API client is installed, it can be used to request data from the datasets listed in the CDS catalog. The API call must follow the syntax:

 

 
# import Module cdsapi
import cdsapi

#initialize the client
c = cdsapi.Client()

#select data set you want to download 
datalist= ['total_precipitation','2m_temperature',]

#API call 
c.retrieve(
   
    'reanalysis-era5-single-levels', #data type
    {
        'product_type': 'reanalysis', #product type
        'format': 'netcdf', #fromat type (two formate are available i.e. netcdf and grib both are multi-dimensional raster )
        'variable': [
            'total_precipitation'  #data 
        ],
        'year': '2019', #select year
        'month': [
            '01', '02', '03',
            '04', '05', '06',
            '07', '08', '09',
            '10', '11', '12',
        ], #select month
        'day': [ 
            '01', '02', '03',
            '04', '05', '06',
            '07', '08', '09',
            '10', '11', '12',
            '13', '14', '15',
            '16', '17', '18',
            '19', '20', '21',
            '22', '23', '24',
            '25', '26', '27',
            '28', '29', '30',
            '31',
        ], #select day
        'time': [
            '00:00',
            '12:00'
        ], #select time
    },
    'total_precipitation.nc') #export format

 

Once you run the API, it will download the file as following

 

2020-03-11 16:15:19,736 INFO Welcome to the CDS
2020-03-11 16:15:19,737 INFO Sending request to https://cds.climate.copernicus.eu/api/v2/resources/reanalysis-era5-single-levels
2020-03-11 16:15:20,582 INFO Request is queued
2020-03-11 16:15:21,769 INFO Request is running
2020-03-11 16:17:15,770 INFO Request is completed

Responses

dinesh

pl sir guide e to correct following error Exception: Missing/incomplete configuration file: C:\Users\Dinesh/.cdsapirc

  • Apr 12, 2020 |

bikesh

Dear Dinesh try to add the cdsapirc file in c:/.cdsapirc and add you key in that file

  • Apr 13, 2020 |

Leave your comment